package main

import (
	"encoding/json"
	"fmt"
)

type Servers struct {
	Servers []Server
}

type Server struct {
	ServerName string
	ServerIP   string
}
/*
func (servers *Servers) ToString() string {
	return "abc"
}*/

func main() {
	simple()
}

func first() {
	str := `{"servers":[{"serverName":"Shanghai_VPN","serverIP":"127.0.0.1"},{"serverName":"Beijing_VPN","serverIP":"127.0.0.2"}]}`
	var servers Servers

	json.Unmarshal([]byte(str), &servers)
	fmt.Println(str)
	fmt.Println(servers)
}

func simple() {
	b := []byte(`{"Name":"Wednesday","Age":6,"Parents":["Gomez","Morticia"]}`)
	var f interface{}
	err := json.Unmarshal(b, &f)

	if err != nil {
		fmt.Printf("error: %v\n", err)
	}

	m := f.(map[string]interface{})
	fmt.Println(m)

	for k, v := range m {
		switch vv := v.(type) {
		case string:
			fmt.Println(k, " is string ", vv)
		case int:
			fmt.Println(k, " is int ", vv)
		case float64:
			fmt.Println(k, " is float64 ", vv)
		case []interface{}:
			fmt.Println(k, " is an array ", vv)
			for i, u := range vv {
				fmt.Println(i, "==", u)
			}

		default:
			fmt.Println(k, " is of a type i done know how to handle ", vv)
		}
	}
}
